package com.pralo.barcodeinfo;


import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DataBase extends SQLiteOpenHelper {

	public static final String TABLE_COMMENTS = "Config";
	public static final String COLUMN_ID = "_id";
	public static final String COLUMN_COMMENT = "field";

	private static final String DATABASE_NAME = "QADDB.db";
	private static final int DATABASE_VERSION = 1;

	// Database creation sql statement
	private static final String DATABASE_CREATE = "create table "
			+ TABLE_COMMENTS + "( " + COLUMN_ID
			+ " integer primary key, " + COLUMN_COMMENT //+ " integer primary key autoincrement, " + COLUMN_COMMENT
			+ " text not null);";

	public DataBase(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase database) {
		database.execSQL(DATABASE_CREATE);
		ContentValues values = new ContentValues();
		values.put(DataBase.COLUMN_ID, "1");
		values.put(DataBase.COLUMN_COMMENT, "0");
		long insertId = database.insert(DataBase.TABLE_COMMENTS, null,	values);
		values.put(DataBase.COLUMN_ID, "2");
		values.put(DataBase.COLUMN_COMMENT, "0");
		insertId = database.insert(DataBase.TABLE_COMMENTS, null,	values);
		values.put(DataBase.COLUMN_ID, "3");
		values.put(DataBase.COLUMN_COMMENT, "0");
		insertId = database.insert(DataBase.TABLE_COMMENTS, null,	values);
		values.put(DataBase.COLUMN_ID, "4");
		values.put(DataBase.COLUMN_COMMENT, "0");
		insertId = database.insert(DataBase.TABLE_COMMENTS, null,	values);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		Log.w(DataBase.class.getName(),
				"Upgrading database from version " + oldVersion + " to "
						+ newVersion + ", which will destroy all old data");
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_COMMENTS);
		onCreate(db);
	}

}
